package practice3;

public abstract class AbstractArithmetic {
    protected int num1;
    protected int num2;
    protected int result;

    public AbstractArithmetic(int num1, int num2) {
        this.num1 = num1;
        this.num2 = num2;
        this.calculate(); // 构造时自动计算
    }

    // 抽象方法：计算结果
    public abstract void calculate();

    // 抽象方法：获取运算符
    public abstract char getOperator();

    // getter方法
    public int getNum1() { return num1; }
    public int getNum2() { return num2; }
    public int getResult() { return result; }

    @Override
    public String toString() {
        return num1 + " " + getOperator() + " " + num2 + " = " + result;
    }
}